var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        page : {
            isend : false,
            doing : false,
            doo : 'admin',
            pdata : {
                op : 'moneylog',
                page : 1,
                status : 0,
                type : 0,
                mtype : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        isIPX : app.globalData.isIPX ? 1 : 0,
        option1: [
            { text: '全部收支', value: 0 },
            { text: '支出记录', value: 1 },
            { text: '收入记录', value: 2 },
        ],
        option2 : [],
    },
    onShow:function(options){
        var self = this;

        self.setData({
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.doing' : false,
        })

        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                    datalist : data.list,
                    params : data.params,
                    shop : data.shop,
                    inited : true,
                    sets : data.set,
                    draw : data.draw,
                    option2 : data.option2,
                });
            },false,function(res){
                app.com.alert( res.data.message,function(){
                    app.globalData.adminurl = app.com.getUrlArgs();
                    if( res.data.errno == 2 ){
                        wx.navigateTo({
                            url : res.data.data.url
                        });
                    }
                });
            });
        });
        wx.setNavigationBarTitle({
            title: '资金管理',
        });
        
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: '资金管理',
            path: '',
        }
    },
    onReachBottom : function(){
        var self = this;

        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    fddraw(){
        var self = this;
        if( self.data.shop.money*1 < self.data.sets.leastdraw*1 ){
            app.com.toast( '最低提现金额'+ self.data.sets.leastdraw*1 +'，余额不足' ); return false;
        }
        app.com.http('admin','POST',{op:'fddraw'},0,true,'','',function(res){
            if (!res.data.errno) {
                app.com.toast(res.data.message,'success',function(){
                    self.setData({
                        'shop.money' : '0.00'
                    });
                });
            }else{
                app.com.toast( res.data.message );
                if( res.data.errno == 2 ){
                    wx.navigateTo({
                        url : res.data.data.url
                    });
                }
                if( res.data.errno == 3 ){
                    setTimeout(function(){
                        wx.navigateTo({
                            url : '/zofui_sales/admin/set'
                        });
                    },1000);
                }                
            }
        });
    },
    onchange(e){
        console.log(e);
        var self = this;
        var value = e.detail;
        var type = e.currentTarget.dataset.type*1;
        var typestr = 'type';
        if(type == 2) typestr = 'mtype';

        self.setData({
            datalist : [],
            ['page.pdata.'+typestr] : value,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
        self.data.ising = false;
    },
    onPullDownRefresh: function () {
        wx.stopPullDownRefresh();
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
})